package no.cicero.testframework.common.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Properties;

public class SafeStringOperators {
    public static String null2empty(final String s) {
        return (s != null) ? s : "";
    }
    public static String null2emptyTrim( final String s ) {
        return null2empty(s).trim();
    }
    public static void readPropertiesFromString(String s, Properties out) throws IOException{
        if(s == null)
            return;
        ByteArrayInputStream stm = new ByteArrayInputStream(s.getBytes());
        out.load(stm);        
    }
    public static String savePropertiesToString(Properties p) throws IOException{
        if(p == null)
            return null;
        ByteArrayOutputStream stm = new ByteArrayOutputStream();
        p.store(stm, null);
        return stm.toString();
    }
}

